﻿Imports System.Data.OleDb
Imports DTO

Public Class TacGiaDAO

    Public Function LayTenTacGia(ByVal tg As TacGiaDTO) As DataTable

        Dim dt As New DataTable
        Dim cn As OleDbConnection
        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim sql As String
        sql = "select * from TacGia where idTacGia= ? "
        'B4: Thuc thi chuoi strSQL
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.Parameters.Add("@idTacGia", OleDbType.Integer)
        cmd.Parameters("@idTacGia").Value = tg.LayIdTacGia
        Dim a As New OleDb.OleDbDataAdapter(sql, cn)
        a.SelectCommand = cmd
        a.Fill(dt)
        cn.Close()
        Return dt
    End Function

    Public Sub ThemTacGiaMoi(ByVal tg As TacGiaDTO)
        Dim kq As Boolean = True

        Dim dt As New DataTable
        Dim cn As OleDbConnection
        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim sql As String = "insert into TacGia (TenTacGia) values(?)"
        Dim cmd As New OleDbCommand(sql, cn)
        cmd.Parameters.Add("@TenTacGia", OleDbType.WChar)
        cmd.Parameters("@TenTacGia").Value = tg.LayTenTacGia()
        cmd.ExecuteNonQuery()
        cn.Close()
    End Sub

    Public Function LayDanhSachTacGia() As DataTable
        Dim dt As New DataTable

        Dim cn As OleDbConnection
        'B1 & B2: Tao chuoi ket noi, mo ket noi bang doi tuong ket noi
        cn = DatabaseProvider.ConnectionData()
        'B3: Tao chuoi strSQL thao tac CSDL
        Dim sql As String = "select * from TacGia "
        Dim a As New OleDb.OleDbDataAdapter(sql, cn)
        a.Fill(dt)
        cn.Close()
        Return dt
    End Function

    'Public Sub XoaTacGia(ByVal tacgia As TacGiaDTO)
    '    Dim cn As OleDbConnection
    '    cn = DatabaseProvider.ConnectionData


    '    Dim sql As String = "update TacGia set  DaXoa = 1 where idTacGia = ? "   '  ' ' ' ''" & idTheLoai.LayIdTheLoai & "'
    '    Dim cmd As New OleDbCommand(sql, cn)
    '    cmd.Parameters.Add("@idTacGia", OleDbType.Integer)
    '    cmd.Parameters("@idTacGia").Value = tacgia.LayIdTacGia


    '    cmd.ExecuteNonQuery()
    '    cn.Close()
    'End Sub

End Class
